<template>
	<h3>编辑通知公告</h3>
	<el-divider />
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="公告标题" prop="name">
    <el-input v-model="addNotice.nocName" placeholder="请输入公告标题"></el-input>
  </el-form-item>
  
  
  <el-form-item label="公告类型" prop="region">
    <el-select v-model="addNotice.nocType" placeholder="请选择公告类型">
      <el-option label="规章制度" value="规章制度"></el-option>
        <el-option label="节假日" value="节假日"></el-option>
        <el-option label="人事调动" value="人事调动"></el-option>
    </el-select>
  </el-form-item>
 
  
  <el-form-item label="正文" prop="desc">
    <el-input type="textarea" rows=17 v-model="addNotice.nocContent"></el-input>
  </el-form-item>
  
  <el-row>
  	<el-col :span="1"></el-col>
  	<el-col :span="23">
  	  <el-button type="primary" @click="saveNotice">立即发布</el-button>
  	  <el-button @click="tiaozhuanlist">返回</el-button>
  	</el-col>
  </el-row>
  <el-form-item>
    
  </el-form-item>
</el-form>

 
</template>


<script>
  import qs from 'qs'
  import { ElMessage } from 'element-plus'
  export default {
    data() {
      return {
        notices:[],
		addNotice:{}
      }
    },
    methods: {
		tiaozhuanlist:function(){
			this.$router.push({ path: "/managenotice" });
		},
		saveNotice(){
			if(this.addNotice.nocName==null||this.addNotice.nocName=="")
			{
				ElMessage.error('请输入公告标题！')
			}
			else if(this.addNotice.nocContent==null||this.addNotice.nocContent=="")
			{
				ElMessage.error('请添加正文！')
			}
			else if(this.addNotice.nocType==null||this.addNotice.nocType=="")
			{
				ElMessage.error('请选择公告类型！')
			}
			else{
			let that=this
			let str=qs.stringify(that.addNotice)
			this.$axios.get("http://localhost:8080/notice/noticeinsert?"+str).then(function(res){
				if(res.data==true)
				{
					ElMessage({
					    message: '发布成功',
					    type: 'success',
					  })
					  
				}
				else{
					ElMessage.error('发布失败！')
				}
				})
				}
			
			
		},
		
		savenoticeInsert(){
			let that=this
			let str=qs.stringify(that.addNotice)
			this.axios.get('http://localhost:8080/notice/noticeinsert?'+str
			).then((res)=>{
				if(res.data==true)
				{
					ElMessage({
					    message: '添加成功！',
					    type: 'success',
					  })
					this.$router.push({ path: "/noticelist" });
					
				    
				}
				else{
					ElMessage.error('添加失败！')
				}
			       
				})
		}
      
    }
  }
  

</script>

<style>
.transition-box {
    margin-bottom: 10px;
    width: 200px;
    height: 100px;
    border-radius: 4px;
    background-color: #409EFF;
    text-align: center;
    color: #fff;
    padding: 40px 20px;
    box-sizing: border-box;
    margin-right: 20px;
  }

</style>